<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="商品库存明细">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">
        label{
            display:inline-block;
            width:80px;
            color: #aaaaaa;
        }

        .info{
            padding: 2px;
        }
    </style>






    <script>
        jQuery(function () {

            $("#cancel").click(function () {
                closeSubIframe();
            });
        });

        layui.use(['form', 'table','laydate'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                laydate = layui.laydate,
                cascader = layui.ajaxCascader,
                util = layui.util;

            renderTable();

            $("#btn-search").click(function () {
                table.reload("table", {where:genSearch(),page: {curr: 1}});
            });

            $("#export").click(function () {
                exportExcel();
            });

        });
        
        function genSearch() {
            return {
                houseId:"${houseId}",
                storeId:"${storeId}",
                goodsId:"${goodsVo.id}",
                search:$("#search").val()
            };
        }


        function renderTable() {
            layui.table.render({
                id:'table',
                elem: '#table',
                toolbar: '#tableToolBar',
                defaultToolbar:['filter'],
                url: "${baseUrl}house/houseQuery/listDetailListByGoods.action",
                where : {
                    houseId:"${houseId}",
                    storeId:"${storeId}",
                    goodsId:"${goodsVo.id}",
                    time:(new Date()).valueOf()
                },
                cols: [[
                    {width:70,title:"序号",templet:function (d) {
                            return genTableIndex(d.close, "作废", d);
                        }},
                    {width: 100, title: '业务日期',style:"font-size:12px;",templet: function (d) {
                            return GMTToDate(d.date);
                        }},
                    {field: 'hNo', width: 130, title: '入库单号',style:"font-size:12px;",templet:'#linkHouseOutInBar'},
                    {field: 'typeName', width: 130, title: '关联业务',style:"font-size:12px;"},
                    {field: 'no', width: 130, title: '关联业务单号',style:"font-size:12px;",templet:'#linkOrderBar'},
                    {field: 'unitName', width: 130, title: '往来单位名称',style:"font-size:12px;"},
                    {field: 'outNumber', width: 100, title: '出库量',style:"font-size:12px;",templet:function (d) {
                        return emptyEntity(d.outNumber) || d.outNumber==0 ? '':d.outNumber;
                        }},
                    {field: 'inNumber', width: 100, title: '入库量',style:"font-size:12px;",templet:function (d) {
                            return emptyEntity(d.inNumber) || d.inNumber==0 ? '':d.inNumber;
                        }},
                    {field: 'storeName', width: 130, title: '门店',style:"font-size:12px;"},
                    {field: 'houseName', minWidth: 130, title: '仓库',style:"font-size:12px;"},
                ]],
                limit: 10,
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 5 //只显示 5 个连续页码
                    ,first: false //不显示首页
                    ,last: false //不显示尾页
                },
                done: function(res, curr, count){
                    setTableLineCss("table",res.data, "close", true, "font-gray-c2c2c2");

                    $(".linkNo").click(function () {
                        openTab($(this).attr("linkTitle"),$(this).attr("linkUrl"));
                    });
                }

            });
        }


        function exportExcel() {
            confirm("是否导出所有的数据?",function () {
                tipLoad("处理中，请稍后");
                post("${baseUrl}house/houseQueryDetail/export.action"+ genParam(genSearch()),{},function (resp) {
                    closeAll();
                    if (resp.code == 1) {
                        downloadFileByForm("${baseUrl}file/excel/temp/"+resp.data);
                    }  else {
                        errTip(resp.msg);
                    }
                });
            });

        }
    </script>

</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="overflow:hidden; padding: 10px 0px">
            <div style="float: left">
                <img id="goodsImg" src="${baseUrl}img/goods/${goodsVo.image}" alt="" style="background-color:#eeeeee;border: 4px solid #eeeeee; border-radius: 4px;width: 97px;height: 97px;"
                      onerror="this.src='${baseUrl}images/noImg.jpg'">
            </div>

            <div style="float: left;padding-left: 20px;">
                <div style="color: #53606b;font-size: 16px;font-weight: bold;">${goodsVo.name}</div>
                <div><label>编  号:</label>${goodsVo.no}</div>
                <div><label>规  格:</label>${goodsVo.norms}</div>
                <div><label>分  类:</label>${goodsVo.type.name}</div>
                <div><label>基本单位:</label>${goodsVo.goodsUnitVoList.get(0).unit.name}</div>
                <div><label>门店仓库:</label>
                    <c:choose>
                        <c:when test="${empty storeId}">
                            全部
                        </c:when>

                        <c:when test="${empty houseId}">
                            ${storeName}

                            <span style="padding:0px 4px 0px 4px;color: #c2c2c2"> &gt; </span>
                            全部
                        </c:when>

                        <c:otherwise>
                            ${storeName}

                            <span style="padding:0px 4px 0px 4px;color: #c2c2c2"> &gt; </span>
                            ${houseName}
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
        </div>

        <div style="height: 16px; background-color: #eeeeee; margin:0px -10px"> </div>

        <div class="layui-inline" style="margin-top: 16px;">
            <div class="layui-input-inline">
                <input type="text" id="search"  name="search" placeholder="编号" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <a class="layui-btn" id="btn-search"><i class="layui-icon layui-icon-search"></i></a>
                <a class="layui-btn layui-btn-primary" id="export">导出</a>
            </div>
        </div>

        <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>

        <script type="text/html" id="linkHouseOutInBar">
            {{#  if((_login_user.viewOtherOrder && _login_user.store.sys) || _login_user.id==d.userId){ }}
            <a class="linkNo" href="javascript:;" linkUrl="${baseUrl}{{d.hUrl}}.action?id={{d.hId}}" linkTitle="入库单详情" >{{d.hNo}}</a>
            {{# }else{ }}
            {{d.hNo}}
            {{# } }}
        </script>

        <script type="text/html" id="linkOrderBar">
            {{#  if((_login_user.viewOtherOrder && _login_user.store.sys) || _login_user.id==d.userId){ }}
            <a class="linkNo" href="javascript:;" linkUrl="${baseUrl}{{d.url}}.action?id={{d.id}}" linkTitle="{{d.typeName}}详情" >{{d.no}}</a>
            {{# }else{ }}
            {{d.no}}
            {{# } }}
        </script>
    </div>
</div>
</body>
<html:loading/>
</html>